<template>
  <div class="app-container">
    <!-- 查询对话框   -->
    <el-dialog
      :title="title"
      v-model="openSearch"
      :close-on-click-modal="false"
      draggable
      width="780px"
      append-to-body
    >
      <el-form
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        label-width="98px"
      >
        <el-col :span="12">
          <el-form-item label="入库单号" prop="rwmRkdh">
            <el-input
              v-model="queryParams.rwmRkdh"
              placeholder="请输入入库单号"
              clearable
              size="small"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="物料代码" prop="rwdWldm">
            <el-input
              v-model="queryParams.rwdWldm"
              placeholder="请输入物料代码"
              clearable
              size="small"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="单据类型" prop="rwmType">
            <el-select
              v-model="queryParams.rwmType"
              clearable
              multiple
              placeholder="请选择入库类型"
            >
              <el-option
                v-for="dict in psTypeOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="入库仓库" prop="rwmCkdm">
            <el-select
              v-model="queryParams.rwmCkdm"
              clearable
              placeholder="请选择入库仓库"
              :disabled="!!depotType"
            >
              <el-option
                v-for="item in storageOptions"
                :key="item.dictValue"
                :label="item.dictLabel"
                :value="item.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="综合查询" prop="totalSelect">
            <el-input
              v-model="queryParams.totalSelect"
              placeholder="请输入综合查询"
              clearable
              size="small"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="厂商代码" prop="rwmCsdm">
            <el-select
              v-model="queryParams.rwmCsdm"
              clearable
              filterable
              placeholder="请选择厂商代码"
            >
              <el-option
                v-for="item in csOptions"
                :key="item.dictValue"
                :label="item.dictLabel"
                :value="item.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="24">
          <el-form-item label="过账日期">
            <el-date-picker
              v-model="daterangeRwmRkry"
              size="small"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :picker-options="pickerOptions"
              :default-time="['00:00:00', '23:59:59']"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="开单日期">
            <el-date-picker
              v-model="daterangeRwmJlry"
              size="small"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :picker-options="pickerOptions"
              :default-time="['00:00:00', '23:59:59']"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item
            style="margin-top: 25px; display: flex; justify-content: flex-end"
          >
            <el-button @click="cancel">取消</el-button>
            <el-button
              type="primary"
              @click="
                openSearch = false;
                handleQuery();
              "
            >
              确认
            </el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-dialog>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-search"
          @click="handleSearch"
          size="small"
          v-hasPermi="['putStorage:rwmReport:list']"
        >
          查询
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          @click="handleExcel(1)"
          v-hasPermi="['putStorage:rwmReport:export']"
          size="small"
          :loading="exportLoading"
        >
          明细数据
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          @click="handleExcel(6)"
          v-hasPermi="['putStorage:rwmReport:export']"
          size="small"
          :loading="exportLoading"
        >
          入库单统计
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          @click="handleExcel(2)"
          v-hasPermi="['putStorage:rwmReport:export']"
          size="small"
          :loading="exportLoading"
        >
          物料统计
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          @click="handleExcel(3)"
          v-hasPermi="['putStorage:rwmReport:export']"
          size="small"
          :loading="exportLoading"
        >
          日期统计
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          @click="handleExcel(4)"
          v-hasPermi="['putStorage:rwmReport:export']"
          size="small"
          :loading="exportLoading"
        >
          厂商统计
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          @click="handleExcel(5)"
          v-hasPermi="['putStorage:rwmReport:export']"
          size="small"
          :loading="exportLoading"
        >
          仓库统计
        </el-button>
      </el-col>
      <Tag type="dot" color="#bb0331">结案</Tag>
      <Tag type="dot" color="#4a86e8">对账中</Tag>
    </el-row>
    <el-tabs v-model="activeTab">
      <el-tab-pane label="明细数据" name="first">
        <el-table
          :cell-style="styleCell"
          border
          stripe
          :height="tableH"
          @scrollBottom="load"
          :data="rwdDetList"
          :header-cell-style="{ 'text-align': 'center' }"
          v-loading="loading"
        >
          <el-table-column
            label="#"
            type="index"
            width="55"
            align="center"
            fixed="left"
          />
          <el-table-column
            label="入库单号"
            align="center"
            width="135"
            prop="rwmDjbh"
          />
          <el-table-column
            label="客户编码"
            align="center"
            width="135"
            prop="itmCustwldm"
          />
          <el-table-column
            label="入库类型"
            :show-overflow-tooltip="true"
            width="100"
            align="center"
            prop="rwmType"
          >
            <template #default="scope">
              <dict-tag :options="psTypeOptions" :value="scope.row.rwmType" />
            </template>
          </el-table-column>
          <el-table-column
            label="厂商"
            :show-overflow-tooltip="true"
            width="140"
            align="center"
            prop="rwmCsdm"
          >
            <template #default="scope">
              <dict-tag :options="csOptions" :value="scope.row.rwmCsdm" />
            </template>
          </el-table-column>
          <el-table-column
            label="仓库"
            class-name="rkck"
            :show-overflow-tooltip="true"
            width="140"
            align="center"
            prop="rwmCkdm"
          >
            <template #default="scope">
              <dict-tag
                :options="allStorageOptions"
                :value="scope.row.rwmCkdm"
              />
            </template>
          </el-table-column>
          <el-table-column
            label="采购单号"
            :show-overflow-tooltip="true"
            width="135"
            align="center"
            prop="rwdCgdh"
          />
          <el-table-column
            label="收货单号"
            :show-overflow-tooltip="true"
            width="135"
            align="center"
            prop="rwmShdh"
          />
          <el-table-column
            label="物料代码"
            align="center"
            prop="rwdWldm"
            width="135"
          />
          <el-table-column label="品名规格" prop="itmPmgg" width="280" />
          <el-table-column
            label="单位"
            :show-overflow-tooltip="true"
            width="60"
            align="center"
            prop="itmDw"
          >
            <template #default="scope">
              <dict-tag :options="unitFlagOptions" :value="scope.row.itmDw" />
            </template>
          </el-table-column>
          <el-table-column
            label="最小包装"
            align="center"
            prop="minPackage"
            width="100"
          />
          <el-table-column
            label="申请数量"
            align="center"
            prop="rwdSqsl"
            width="100"
          />
          <el-table-column
            label="允许数量"
            align="center"
            prop="rwdOksl"
            width="100"
          />
          <el-table-column
            label="拒收数量"
            :show-overflow-tooltip="true"
            width="100"
            align="center"
            prop="rwdNgsl"
          />
          <el-table-column label="入库数量" align="center" prop="rwdRksl" />
          <el-table-column label="单价" align="center" prop="rwdMoney" />
          <el-table-column label="存放位置" align="center" prop="rwdCwdm">
            <template #default="scope">
              <dict-tag
                :options="allStorageOptions"
                :value="scope.row.rwdCwdm"
              />
            </template>
          </el-table-column>
          <el-table-column
            label="检验结果"
            :show-overflow-tooltip="true"
            width="100"
            align="center"
            prop="rwdJyjg"
          >
            <template #default="scope">
              <dict-tag :options="jyjgDict" :value="scope.row.rwdJyjg" />
            </template>
          </el-table-column>
          <el-table-column
            label="检验描述"
            :show-overflow-tooltip="true"
            width="100"
            align="center"
            prop="rwdJydesc"
          />
          <el-table-column
            label="收货单号"
            :show-overflow-tooltip="true"
            align="center"
            prop="rwmShdh"
            width="180"
          />
          <el-table-column
            label="备注"
            :show-overflow-tooltip="true"
            width="100"
            align="center"
            prop="rwmDesc"
          />
          <el-table-column
            label="开单人员"
            :show-overflow-tooltip="true"
            width="100"
            align="center"
            prop="rwmJlry"
          />
          <el-table-column
            label="开单日期"
            :show-overflow-tooltip="true"
            width="150"
            align="center"
            prop="rwmJlrq"
          >
            <template #default="scope">
              <span>{{
                parseTime(scope.row.rwmJlrq, "{y}-{m}-{d} {h}:{i}:{s}")
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="检验人员"
            :show-overflow-tooltip="true"
            width="100"
            align="center"
            prop="rwmJyry"
          />
          <el-table-column
            label="检验日期"
            :show-overflow-tooltip="true"
            width="150"
            align="center"
            prop="rwmJyrq"
          >
            <template #default="scope">
              <span>{{
                parseTime(scope.row.rwmJyrq, "{y}-{m}-{d} {h}:{i}:{s}")
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="入库人员"
            :show-overflow-tooltip="true"
            width="100"
            align="center"
            prop="rwdRkry"
          />
          <el-table-column
            label="入库日期"
            :show-overflow-tooltip="true"
            width="150"
            align="center"
            prop="rwdRkrq"
          >
            <template #default="scope">
              <span>{{
                parseTime(scope.row.rwdRkrq, "{y}-{m}-{d} {h}:{i}:{s}")
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="过账人员"
            :show-overflow-tooltip="true"
            width="100"
            align="center"
            prop="rwmGzry"
          />
          <el-table-column
            label="过账日期"
            :show-overflow-tooltip="true"
            width="150"
            align="center"
            prop="rwmGzrq"
          />
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="入库单统计" name="six">
        <el-table
          border
          stripe
          @scrollBottom="load6"
          :height="tableH"
          :data="rwdRkdList"
          v-loading="loading"
        >
          <el-table-column
            label="#"
            type="index"
            width="55"
            align="center"
            fixed="left"
          />
          <el-table-column
            label="入库单号"
            align="center"
            width="135"
            prop="rwmDjbh"
          />
          <el-table-column
            label="客户编码"
            align="center"
            width="135"
            prop="itmCustwldm"
          />
          <el-table-column
            label="入库类型"
            :show-overflow-tooltip="true"
            width="100"
            align="center"
            prop="rwmType"
          >
            <template #default="scope">
              <dict-tag :options="psTypeOptions" :value="scope.row.rwmType" />
            </template>
          </el-table-column>
          <el-table-column
            label="厂商"
            :show-overflow-tooltip="true"
            width="140"
            align="center"
            prop="rwmCsdm"
          >
            <template #default="scope">
              <dict-tag :options="csOptions" :value="scope.row.rwmCsdm" />
            </template>
          </el-table-column>
          <el-table-column
            label="仓库"
            class-name="rkck"
            :show-overflow-tooltip="true"
            width="140"
            align="center"
            prop="rwmCkdm"
          >
            <template #default="scope">
              <dict-tag
                :options="allStorageOptions"
                :value="scope.row.rwmCkdm"
              />
            </template>
          </el-table-column>
          <el-table-column
            label="物料代码"
            align="center"
            prop="rwdWldm"
            width="135"
          />
          <el-table-column label="品名规格" prop="itmPmgg" width="280" />
          <el-table-column
            label="单位"
            :show-overflow-tooltip="true"
            width="60"
            align="center"
            prop="itmDw"
          >
            <template #default="scope">
              <dict-tag :options="unitFlagOptions" :value="scope.row.itmDw" />
            </template>
          </el-table-column>
          <el-table-column
            label="最小包装"
            align="center"
            prop="minPackage"
            width="100"
          />
          <el-table-column
            label="申请数量"
            align="center"
            prop="rwdSqsl"
            width="100"
          />
          <el-table-column
            label="允许数量"
            align="center"
            prop="rwdOksl"
            width="100"
          />
          <el-table-column
            label="拒收数量"
            :show-overflow-tooltip="true"
            width="100"
            align="center"
            prop="rwdNgsl"
          />
          <el-table-column label="入库数量" align="center" prop="rwdRksl" />
          <el-table-column label="单价" align="center" prop="rwdMoney" />
          <el-table-column
            label="检验结果"
            :show-overflow-tooltip="true"
            width="100"
            align="center"
            prop="rwdJyjg"
          >
            <template #default="scope">
              <dict-tag :options="jyjgDict" :value="scope.row.rwdJyjg" />
            </template>
          </el-table-column>
          <el-table-column
            label="检验描述"
            :show-overflow-tooltip="true"
            width="100"
            align="center"
            prop="rwdJydesc"
          />
          <el-table-column
            label="收货单号"
            :show-overflow-tooltip="true"
            align="center"
            prop="rwmShdh"
            width="180"
          />
          <el-table-column
            label="备注"
            :show-overflow-tooltip="true"
            width="100"
            align="center"
            prop="rwmDesc"
          />
          <el-table-column
            label="开单人员"
            :show-overflow-tooltip="true"
            width="100"
            align="center"
            prop="rwmJlry"
          />
          <el-table-column
            label="开单日期"
            :show-overflow-tooltip="true"
            width="150"
            align="center"
            prop="rwmJlrq"
          >
            <template #default="scope">
              <span>{{
                parseTime(scope.row.rwmJlrq, "{y}-{m}-{d} {h}:{i}:{s}")
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="入库人员"
            :show-overflow-tooltip="true"
            width="100"
            align="center"
            prop="rwdRkry"
          />
          <el-table-column
            label="入库日期"
            :show-overflow-tooltip="true"
            width="150"
            align="center"
            prop="rwdRkrq"
          >
            <template #default="scope">
              <span>{{
                parseTime(scope.row.rwdRkrq, "{y}-{m}-{d} {h}:{i}:{s}")
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="过账人员"
            :show-overflow-tooltip="true"
            width="100"
            align="center"
            prop="rwmGzry"
          />
          <el-table-column
            label="过账日期"
            :show-overflow-tooltip="true"
            width="100"
            align="center"
            prop="rwmGzrq"
          />
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="按物料统计" name="second">
        <el-table
          border
          stripe
          @scrollBottom="load2"
          :height="tableH"
          :data="rwdWldmList"
          v-loading="loading"
        >
          <el-table-column
            label="#"
            type="index"
            width="55"
            align="center"
            fixed="left"
          />
          <el-table-column
            label="物料代码"
            align="center"
            prop="rwdWldm"
            width="135"
          />
          <el-table-column
            label="客户代码"
            align="center"
            width="135"
            prop="itmCustwldm"
          />
          <el-table-column
            label="品名规格"
            align="center"
            prop="itmPmgg"
            width="280"
          />
          <el-table-column
            label="单位"
            :show-overflow-tooltip="true"
            width="60"
            align="center"
            prop="itmDw"
          >
            <template #default="scope">
              <dict-tag :options="unitFlagOptions" :value="scope.row.itmDw" />
            </template>
          </el-table-column>
          <el-table-column
            label="申请数量"
            align="center"
            prop="rwdSqsl"
            width="100"
          />
          <el-table-column
            label="允许数量"
            align="center"
            prop="rwdOksl"
            width="100"
          />
          <el-table-column
            label="拒收数量"
            :show-overflow-tooltip="true"
            width="100"
            align="center"
            prop="rwdNgsl"
          ></el-table-column>
          <el-table-column label="入库数量" align="center" prop="rwdRksl" />
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="按日期统计" name="third">
        <el-table
          border
          stripe
          :height="tableH"
          @scrollBottom="load3"
          :data="rwdDateTotal"
          v-loading="loading"
        >
          <el-table-column
            label="#"
            type="index"
            width="55"
            align="center"
            fixed="left"
          />
          <el-table-column
            label="过账日期"
            :show-overflow-tooltip="true"
            width="150"
            align="center"
            prop="rwmGzrq"
          />
          <el-table-column
            label="物料代码"
            align="center"
            prop="rwdWldm"
            width="135"
          />
          <el-table-column
            label="客户代码"
            align="center"
            width="135"
            prop="itmCustwldm"
          />
          <el-table-column
            label="品名规格"
            align="center"
            prop="itmPmgg"
            width="280"
          />
          <el-table-column
            label="单位"
            :show-overflow-tooltip="true"
            width="60"
            align="center"
            prop="itmDw"
          >
            <template #default="scope">
              <dict-tag :options="unitFlagOptions" :value="scope.row.itmDw" />
            </template>
          </el-table-column>
          <el-table-column
            label="申请数量"
            align="center"
            prop="rwdSqsl"
            width="100"
          />
          <el-table-column
            label="允许数量"
            align="center"
            prop="rwdOksl"
            width="100"
          />
          <el-table-column
            label="拒收数量"
            :show-overflow-tooltip="true"
            width="100"
            align="center"
            prop="rwdNgsl"
          />
          <el-table-column label="入库数量" align="center" prop="rwdRksl" />
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="按厂商统计" name="foruth">
        <el-table
          border
          stripe
          :height="tableH"
          @scrollBottom="load4"
          :data="rwdCsTotal"
          v-loading="loading"
        >
          <el-table-column
            label="#"
            type="index"
            width="55"
            align="center"
            fixed="left"
          />
          <el-table-column
            label="厂商"
            :show-overflow-tooltip="true"
            width="140"
            align="center"
            prop="rwmCsdm"
          >
            <template #default="scope">
              <dict-tag :options="csOptions" :value="scope.row.rwmCsdm" />
            </template>
          </el-table-column>
          <el-table-column
            label="物料代码"
            align="center"
            prop="rwdWldm"
            width="135"
          />
          <el-table-column
            label="品名规格"
            align="center"
            prop="itmPmgg"
            width="280"
          />
          <el-table-column
            label="客户代码"
            align="center"
            width="135"
            prop="rwdCgdh"
          />
          <el-table-column
            label="单位"
            :show-overflow-tooltip="true"
            width="60"
            align="center"
            prop="itmDw"
          >
            <template #default="scope">
              <dict-tag :options="unitFlagOptions" :value="scope.row.itmDw" />
            </template>
          </el-table-column>
          <el-table-column
            label="申请数量"
            align="center"
            prop="rwdSqsl"
            width="100"
          />
          <el-table-column
            label="允许数量"
            align="center"
            prop="rwdOksl"
            width="100"
          />
          <el-table-column
            label="拒收数量"
            :show-overflow-tooltip="true"
            width="100"
            align="center"
            prop="rwdNgsl"
          />
          <el-table-column label="入库数量" align="center" prop="rwdRksl" />
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="按仓库统计" name="fifth">
        <el-table
          border
          stripe
          :height="tableH"
          @scrollBottom="load5"
          :data="rwdCkTotal"
          v-loading="loading"
        >
          <el-table-column
            label="#"
            type="index"
            width="55"
            align="center"
            fixed="left"
          />
          <el-table-column
            label="仓库"
            class-name="rkck"
            :show-overflow-tooltip="true"
            width="140"
            align="center"
            prop="rwmCkdm"
          >
            <template #default="scope">
              <dict-tag
                :options="allStorageOptions"
                :value="scope.row.rwmCkdm"
              />
            </template>
          </el-table-column>
          <el-table-column
            label="物料代码"
            align="center"
            prop="rwdWldm"
            width="135"
          />
          <el-table-column
            label="品名规格"
            align="center"
            prop="itmPmgg"
            min-width="280"
          />
          <el-table-column
            label="客户代码"
            align="center"
            width="135"
            prop="rwdCgdh"
          />
          <el-table-column
            label="单位"
            :show-overflow-tooltip="true"
            width="60"
            align="center"
            prop="itmDw"
          >
            <template #default="scope">
              <dict-tag :options="unitFlagOptions" :value="scope.row.itmDw" />
            </template>
          </el-table-column>
          <el-table-column
            label="申请数量"
            align="center"
            prop="rwdSqsl"
            width="100"
          />
          <el-table-column
            label="入库数量"
            align="center"
            prop="rwdRksl"
            width="100"
          />
        </el-table>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import { getCs } from "@/api/putStorage/putStorageAdd";
import { getPstorageType } from "@/api/repertory/putstorage";
import { getAll, getstorageType } from "@/api/repertory/Storage";
import { exportRwmReport, listData } from "@/api/putStorage/rwmReport";
import debounce from "lodash/debounce";

export default {
  name: "RwmReport",
  data() {
    return {
      depotType: this.$route.query.depotType,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      serachChildren: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      tableH: document.body.clientHeight - 300,
      tableHChild: document.body.clientHeight - 280,
      single: true,
      activeTab: "first",
      // 非多个禁用
      multiple: true,
      rwdDetList: [],
      rwdDateTotal: [],
      rwdCsTotal: [],
      rwdCkTotal: [],
      rwdWldmList: [],
      rwdRkdList: [],
      // 显示搜索条件
      showSearch: true,
      openSearch: false,
      openChildren: false,
      // 总条数
      total: 0,
      total2: 0,
      total3: 0,
      total4: 0,
      total5: 0,
      total6: 0,
      //入库类型
      psTypeOptions: [],

      //存储厂商
      csOptions: [],

      //有效存储仓库
      storageOptions: [],
      //检验结果字典
      jyjgDict: [
        { dictLabel: "允收", dictValue: "OK", listClass: "default" },
        { dictLabel: "拒收", dictValue: "NG", listClass: "default" },
        { dictLabel: "特采", dictValue: "TC", listClass: "default" },
      ],

      //所以存储仓库
      allStorageOptions: [],

      //有效存储储位
      cWOptions: [],

      //所有存储储位
      allCwOptions: [],

      // 弹出层标题
      title: "",
      addDate: true,
      // 是否显示弹出层
      open: false,
      // 建立日期时间范围
      daterangeRwmJlry: [
        this.$moment().startOf("month").toDate(),
        this.$moment().add(100, "year").endOf("month").toDate(),
      ],
      daterangeRwmRkry: [
        this.$moment().startOf("month").toDate(),
        this.$moment().add(100, "year").endOf("month").toDate(),
      ],
      rkmxList: [],
      rktjList: [],
      qgmxList: [],
      rowData: null,
      qgdDetCountList: [],
      serachAddList: [],
      unitFlagOptions: [],
      selectioned: [],
      type1: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 30,
        rwmRkdh: null,
        rwmType: null,
        rwmCkdm: null,
        rwmCsdm: null,
        rwdWldm: null,
        totalSelect: null,
        index: 0,
      },

      // 表单参数
      form: {},
      // 表单校验
      //日期初始化
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
    };
  },
  created() {
    //入库类型字典
    getPstorageType(0).then((response) => {
      this.psTypeOptions = response.data;
      for (let i of this.psTypeOptions) {
        i.listClass = "default";
      }
    });
    //单位
    this.getDicts("sys_unit").then((response) => {
      this.unitFlagOptions = response.data;
    });
    //存放位置
    getstorageType("0").then((response) => {
      this.cWOptions = response.data;

      for (let item of this.cWOptions) {
        item.dictLabel = item.storageDefaultstorage;
        item.listClass = "default";
        item.dictValue = item.storageId + "";
      }
    });

    getstorageType("0").then((response) => {
      for (let item of response.data) {
        if (!this.depotType && item.storageId == 9) {
          continue;
        }
        item.dictLabel = item.storageName;
        item.listClass = "default";
        item.dictValue = item.storageId + "";
        this.storageOptions.push(item);
      }
    });

    getAll().then((response) => {
      this.allCwOptions = response.data;

      for (let item2 of this.allCwOptions) {
        item2.dictLabel = item2.storageDefaultstorage;

        item2.listClass = "default";
        item2.dictValue = item2.storageId + "";
      }
    });

    getAll().then((response) => {
      this.allStorageOptions = response.data;

      for (let item of this.allStorageOptions) {
        item.dictLabel = item.storageName;
        item.listClass = "default";
        item.dictValue = item.storageId + "";
      }
    });

    getCs().then((response) => {
      this.csOptions = response.data;
      for (let item of this.csOptions) {
        item.dictLabel = item.csmCs;
        item.listClass = "default";
        item.dictValue = item.csmCsdm;
      }
    });

    if (this.depotType) {
      this.queryParams.rwmCkdm = "9";
      this.queryParams.depotType = this.depotType;
    }
    this.getList();
  },
  methods: {
    /** 查询来料进货入库开单列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeRwmRkry && "" != this.daterangeRwmRkry) {
        this.queryParams.params["beginRkTime"] = this.moment(
          this.daterangeRwmRkry[0]
        ).format("YYYY-MM-DD HH:mm:ss");
        this.queryParams.params["endRkTime"] =
          this.moment(this.daterangeRwmRkry[1]).format("YYYY-MM-DD ") +
          "23:59:59";
      }
      if (null != this.daterangeRwmJlry && "" != this.daterangeRwmJlry) {
        this.queryParams.params["beginJlTime"] = this.moment(
          this.daterangeRwmJlry[0]
        ).format("YYYY-MM-DD HH:mm:ss");
        this.queryParams.params["endJlTime"] =
          this.moment(this.daterangeRwmJlry[1]).format("YYYY-MM-DD ") +
          "23:59:59";
      }
      listData(this.queryParams).then((response) => {
        // 明细
        this.rwdDetList = this.rwdDetList.concat(response.data.list1.rows);
        this.total = response.data.list1.total;
        // 物料
        this.rwdWldmList = this.rwdWldmList.concat(response.data.list2.rows);
        this.total2 = response.data.list2.total;
        // 日期
        this.rwdDateTotal = this.rwdDateTotal.concat(response.data.list3.rows);
        this.total3 = response.data.list3.total;
        // 厂商
        this.rwdCsTotal = this.rwdCsTotal.concat(response.data.list4.rows);
        this.total4 = response.data.list4.total;
        // 仓库
        this.rwdCkTotal = this.rwdCkTotal.concat(response.data.list5.rows);
        this.total5 = response.data.list5.total;
        // 按入库单
        this.rwdRkdList = this.rwdRkdList.concat(response.data.list6.rows);
        this.total6 = response.data.list6.total;

        this.loading = false;
      });
    },
    load() {
      if (
        this.queryParams.pageNum <
        Math.ceil(this.total / this.queryParams.pageSize)
      ) {
        this.queryParams.pageNum++;
        this.getList();
      }
      return 0;
    },
    load2() {
      if (
        this.queryParams.pageNum <
        Math.ceil(this.total2 / this.queryParams.pageSize)
      ) {
        this.queryParams.pageNum++;
        this.getList();
      }
      return 0;
    },
    load3() {
      if (
        this.queryParams.pageNum <
        Math.ceil(this.total3 / this.queryParams.pageSize)
      ) {
        this.queryParams.pageNum++;
        this.getList();
      }
      return 0;
    },
    load4() {
      if (
        this.queryParams.pageNum <
        Math.ceil(this.total4 / this.queryParams.pageSize)
      ) {
        this.queryParams.pageNum++;
        this.getList();
      }
      return 0;
    },
    load5() {
      if (
        this.queryParams.pageNum <
        Math.ceil(this.total5 / this.queryParams.pageSize)
      ) {
        this.queryParams.pageNum++;
        this.getList();
      }
      return 0;
    },
    load6() {
      if (
        this.queryParams.pageNum <
        Math.ceil(this.total6 / this.queryParams.pageSize)
      ) {
        this.queryParams.pageNum++;
        this.getList();
      }
      return 0;
    },
    handleSearch() {
      this.openSearch = true;
      this.title = "查询来料进货统计分析";
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openSearch = false;
      this.openChildren = false;
    },

    /** 搜索按钮操作 */
    handleQuery: debounce(function () {
      this.queryParams.pageNum = 1;
      this.rwdDetList = [];
      this.rwdWldmList = [];
      this.rwdDateTotal = [];
      this.rwdCsTotal = [];
      this.rwdCkTotal = [];
      this.rwdRkdList = [];
      this.getList();
      this.openSearch = false;
    }, 500),

    clickRwm(row) {},
    //导出Excel
    handleExcel(index) {
      this.exportLoading = true;
      this.queryParams.index = index;
      const queryParams = this.queryParams;
      exportRwmReport(queryParams).then((response) => {
        this.download(response.msg);
        this.queryParams.index = 0;
        this.exportLoading = false;
      });
    },
    styleCell({ row, column, rowIndex, columnIndex }) {
      if (row.billZtbz == "1") {
        return { color: "#4a86e8" };
      } else if (row.billZtbz == "2") {
        return { color: "#bb0331" };
      }
    },
  },
};
</script>

<style lang="scss" scoped></style>
